package org.testis.guiappsmodule.services;

import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;
import org.testis.guiappsmodule.data.GuiAppsModuleDataObject;
import org.testis.logging.AtofLogLevel;
import org.testis.logging.LogSenderService;
import org.testis.services.AtofModuleAction;
import org.testis.services.AtofModuleService;


/**
 *
 * @author nurhat
 */
public class GuiAppsExitCodeVerificationAction extends AtofModuleAction
{

    @Override
    public boolean operateRequest(AtofModuleService request)
    {
        GuiAppsModuleDataObject dataObj =
            (GuiAppsModuleDataObject) request.getDataObj();
        String expectedResult = dataObj.getExpectedExitCode();
        if (expectedResult == null) {
            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "Expected exit code result should not be null...");
        }
        if (expectedResult.equals(dataObj.getExitCode())) {
            LogSenderService.putMessageOnQueue(
                "GuiAppExitCodeVerificationAction",
                AtofLogLevel.INFO,
                "Expected exit code result was verified. ExitCode:" + dataObj.
                getExitCode() + " Expected ExitCode:" +
                expectedResult,
                dataObj.getMessageId());
            return true;
        }
        LogSenderService.putMessageOnQueue(
            "GuiAppExitCodeVerificationAction",
            AtofLogLevel.ERROR,
            "Expected exit code result was not verified. ExitCode:" + dataObj.
            getExitCode() + " Expected ExitCode:" +
            expectedResult,
            dataObj.getMessageId());
        return false;

    }
}
